package com.example.testapp.activity.fragment;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.testapp.R;
import com.example.testapp.activity.activity.read.CanvasActivity;
import com.example.testapp.activity.activity.read.HttpViewActivity;
import com.example.testapp.activity.activity.read.ListViewActivity;
import com.example.testapp.activity.activity.read.PathActivity;

/**
 * Created by l on 2016/7/2.
 */
public class ReadFragment extends BaseFragment {

    private static final String ARG_PARAM1 = "param1";
    private  String  mParam1;

    private ProgressDialog mDialog;
    private LinearLayout mCanvasLayout = null;
    private LinearLayout mPathLayout = null;
    private LinearLayout mListLayout = null;
    private LinearLayout mWebLayout = null;


    public ReadFragment(){

    }

    public ReadFragment newInstance(String param) {
        ReadFragment fragment = new ReadFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getArguments() != null){
            //mParam1 = getArguments().getString(ARG_PARAM1);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_read, container, false);

        initData();
        initView(view);
        return view;
    }

    private void initData() {
        mDialog = new ProgressDialog(getActivity());
        mDialog.setMessage("加载中...");
        mDialog.setCancelable(true);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.show();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                    mDialog.dismiss();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private void initView(View view) {
        mCanvasLayout = (LinearLayout)view.findViewById(R.id.canvasLayout);
        mPathLayout = (LinearLayout)view.findViewById(R.id.pathLayout);
        mListLayout = (LinearLayout)view.findViewById(R.id.listLayout);
        mWebLayout = (LinearLayout)view.findViewById(R.id.webLayout);
        initListener();
    }

    private void initListener() {
        mCanvasLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), CanvasActivity.class);

                startActivity(intent);
            }
        });

        mPathLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), PathActivity.class);

                startActivity(intent);
            }
        });

        mListLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), ListViewActivity.class);

                startActivity(intent);
            }
        });

        mWebLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), HttpViewActivity.class);

                startActivity(intent);
            }
        });
    }
}
